﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Text.RegularExpressions;

namespace UnrealConverterLogic
{
    public partial class UnrealConverter
    {
        public static List<Label> lUUGridArray;
        public static List<Label> lMaxGridArray;

        public static void SetGridArrays()
        {
            lUUGridArray = new List<Label>();
            lMaxGridArray = new List<Label>();
            foreach (Control c in formMain.Controls.Find("gBUUGrid", false)[0].Controls)
            {
                if (c.Name.Contains("UU"))
                {
                    ((Label)c).Text = "";
                    lUUGridArray.Add((Label)c);
                }
            }
            foreach (Control c in formMain.Controls.Find("gBMaxGrid", false)[0].Controls)
            {
                if (c.Name.Contains("Max"))
                {
                    ((Label)c).Text = "";
                    lMaxGridArray.Add((Label)c);
                }
            }
        }
        public static void UpdateGridArrays()
        {
            if( lUUGridArray != null ) UpdateGridArray(lUUGridArray.ToArray(), CurrentConversion.UnrealUnits);
            if( lMaxGridArray != null )UpdateGridArray(lMaxGridArray.ToArray(), CurrentConversion.MaxUnits);
        }
        public static void UpdateGridArray(Label[] lGridArray, double value)
        {
            double fResult;
            double divisor;
            foreach (Label l in lGridArray)
            {
                divisor = Int32.Parse(Regex.Match(l.Name, @"[0-9]+").Value);
                l.Text = "";
                l.Visible = true;
                fResult = value / divisor;
                bool cleanDivide = (value % divisor) == 0 ? true : false;
                int iResult = (int)fResult;
                if (iResult > 0 && cleanDivide)
                {
                    l.Text = iResult.ToString();
                    l.ForeColor = Color.SteelBlue;
                }
            }
        }

    }
}
